package cn.iocoder.yudao.module.business.dal.mysql.trainUnit;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;

import cn.iocoder.yudao.module.business.controller.admin.trainUnit.vo.TrainUnitPageReqVO;
import cn.iocoder.yudao.module.business.dal.dataobject.trainUnit.TrainUnitDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Set;

/**
 * 培训单位 Mapper
 *
 * @author admin
 */
@Mapper
public interface TrainUnitMapper extends BaseMapperX<TrainUnitDO> {

    default PageResult<TrainUnitDO> selectPage(TrainUnitPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TrainUnitDO>()
                .likeIfPresent(TrainUnitDO::getTrainUnitName, reqVO.getTrainUnitName())
                .orderByDesc(TrainUnitDO::getId));
    }


    /**
     * 根据名称查询
     * @param name 名称
     * @return 培训学校
     */
    default TrainUnitDO selectByName(String name){
        return selectOne(new LambdaQueryWrapper<TrainUnitDO>()
            .eq(TrainUnitDO::getTrainUnitName,name)
            .last("limit 1")
        );
    }

    default List<TrainUnitDO> selectListByRelationIds(Set<Long> relationIds){
        return selectList(new LambdaQueryWrapper<TrainUnitDO>()
                .in(TrainUnitDO::getRelationId,relationIds));
    }

    void updateTrainUnitList(List<TrainUnitDO> list);

    void deleteTrainUnitList(@Param("list") List<Long> unitNames);
}